package com.xdxc.controller;


import com.xdxc.model.entity.User;
import com.xdxc.response.Result;
import com.xdxc.service.AuthService;
import com.xdxc.service.UserService;
import com.xdxc.vo.LoginAdminVo;
import com.xdxc.vo.RegisterAdmin;
import com.xdxc.vo.UserLoginVo;
import com.xdxc.vo.UserRegisterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class LoginController {


    @Autowired
    private AuthService authService;
    @Autowired
    private UserService userService;

    @PostMapping("/admin/register")
    public Boolean registerByUserName(@RequestBody RegisterAdmin registerAdmin){
       boolean bo  = authService.registerByUsername(registerAdmin);
       return bo;
    }

    @PostMapping("/admin/login")
    public Result loginByUserName(@RequestBody LoginAdminVo loginAdminVo){
        Result bo  = authService.loginByUserName(loginAdminVo);
        return bo;
    }

    @PostMapping( "/user/login")
    public Result loginByEmail(@RequestBody UserLoginVo userLoginVo){
        User user  = authService.loginByEmail(userLoginVo);
        return Result.success(user);
    }
    @PostMapping("/user/register")
    public Boolean registerByEmail(@RequestBody UserRegisterVo userRegisterVo){
       Boolean bo= userService.registerByEmail(userRegisterVo);
        return bo;
    }
}
